<?php

include_once 'templates/global/agent-login-prevent.php';
include_once '../web.php';
require_once '../Controller/agentManagementController.php';
$agentManagementController = new agentManagementController();
include_once '../Model/DAL/Functions.php';
$func = new Functions();


$action = "";
$tab = "";

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $action = (isset($_POST['action']) != NULL) ? $_POST['action'] : '';
    $tab = (isset($_POST['tab']) != NULL) ? $_POST['tab'] : '';
} else {
    $action = (isset($_GET['action']) != NULL) ? $_GET['action'] : '';
    $tab = (isset($_GET['tab']) != NULL) ? $_GET['tab'] : '';
}

// Khi chua chọn tab
if ($tab === "") {
    include_once 'templates/managements/agent/tmp-agent-management-taikhoan.php';
}

// Khi chọn tab Tạo Mới User & Submit
else if ($tab === "createnewuser") {
    // Khi chọn tab Tạo Mới User
    if ($action === "" || $action === "createnewuser") {
        include_once 'templates/managements/agent/tmp-agent-management-taikhoan.php';
    }
    // Khi Submit Tạo Mới User
    else if ($action == 'createuser') {
        $agentManagementController->createUser();
    }
}

// Khi chọn tab Danh Sách User
else if ($tab === "listofuser") {
    // Khi chọn tab Danh Sách User
    if ($action === "" || $action === "listofuser") {
        $result = $agentManagementController->getAllPlayer();
        $limit = $result["Limit"];
        $range = $result["Range"];
        $start = $result["Start"];
        $total = $result["Total"];
        $arr = $result["Data"];
        include_once 'templates/managements/agent/tmp-agent-management-taikhoan.php';
    }
    // Khi chọn User Update
    else if ($action == 'loaddetailuserupdate') {
        $arr = $agentManagementController->loadAccountDetail();
        include_once 'templates/managements/agent/tmp-agent-management-taikhoan.php';
    }
    // Khi Update User
    else if ($action == 'updateuser') {
        $agentManagementController->updatePlayer();
    }
}


// Khi chọn tab Danh Sách Balance User
else if ($tab === "listofuserbalance") {
    // Khi chọn tab Danh Sách User Balance
    if ($action === "" || $action === "listofuserbalance") {
        $result = $agentManagementController->getAllPlayerBalance();
        $limit = $result["Limit"];
        $range = $result["Range"];
        $start = $result["Start"];
        $total = $result["Total"];
        $arr = $result["Data"];
        include_once 'templates/managements/agent/tmp-agent-management-taikhoan.php';
    }
}


// Khi chọn tab Tai Khoan User
else if ($tab === "accountbalanceuser") {
    if ($action === "" || $action === "accountbalanceuser") {
        $arr = $agentManagementController->getAccountBalance();
        include_once 'templates/managements/agent/tmp-agent-management-taikhoan.php';
    }
}


// Khi chọn tab Update Password User
else if ($tab === "changepassworduser") {
    // Khi chọn tab Update Password User
    if ($action === "" || $action === "changepassworduser") {
        $arr = $agentManagementController->preChangePassword();
        include_once 'templates/managements/agent/tmp-agent-management-taikhoan.php';
    }
    // Khi Submit Update Password User
    else if ($action == 'changepassword') {
        $agentManagementController->changepassword();
    }
}